package com.ymatou.iapi.payment.testcase.old;

import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.payment.parameter.*;
import com.ymatou.iapi.payment.service.*;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.PaymentProxyCallService;
import com.ymttest.database.model.PPBussinessOrder;
import com.ymttest.database.model.PPPayment;
import com.ymttest.database.model.RefundRequest;
import com.ymttest.database.sqlwapper.PaymentDefaultWapper;
import com.ymttest.utils.TestDataManager;

/**
 * 部分退款接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_AcquireRefund {
	private static AcquireRefundBean acquirerefundBean;
	private static AcquireRefundCall acquirerefundCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("部分退款接口");
	}

	@Before
	public void caseUp() {
		acquirerefundBean = new AcquireRefundBean();
		acquirerefundCall = new AcquireRefundCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(acquirerefundCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcquireRefund_001() {
		Logger.start(true, "输入全部退款金额,收单成功,生成RefundBatchNos");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
//			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("0", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			verifyDB(aqb, acquirerefundBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AcquireRefund_002() {
		Logger.start(true, "输入部分退款金额,收单成功");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
//			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("0", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			verifyDB(aqb, acquirerefundBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AcquireRefund_003() {
		Logger.start(true, "多次退款,输入部分退款金额总和不超过总金额,收单成功");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
//			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(1);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			
			//这里做一次退款执行
			PaymentDefaultWapper paymentwapper = new PaymentDefaultWapper();
			PPBussinessOrder ppb = paymentwapper.selectPPBussinessorderByTraceId(aqb.getTraceId()).get(0);
			String businessoid = ppb.getBussinessOrderId();
			PPPayment ppm = paymentwapper.selectPPPaymentByBussinessOrderId(businessoid).get(0);
			String trandno = ppm.getPaymentId();
			List<RefundRequest> mlist = paymentwapper.selectRefundRequestByPaymentId(trandno);
			PaymentProxyCallService.executeRefund(mlist.get(0), "10");
			acquirerefundBean.setTradeType(1);
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundCall.callService();
			//主键不能重复导致，更新数据库后应该可以成功
			Logger.verifyEquals("0", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			verifyDB(aqb, acquirerefundBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AcquireRefund_004() {
		Logger.start(true, "单次输入退款金额超过总金额,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt(aqb.getPayPrice()+1);
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("3501", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("拒绝退款", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
			Logger.verifyEquals("false", acquirerefundCall.getString("IsSuccess"), "验证IsSuccess");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AcquireRefund_005() {
		Logger.start(true, "多次退款,输入部分退款金额总和超过总金额,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
//			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(1);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			acquirerefundBean.setRefundAmt("7");
			acquirerefundBean.setTradeType(1);
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundCall.callService();
			Logger.verifyEquals("3501", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("拒绝退款", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
			Logger.verifyEquals("false", acquirerefundCall.getString("IsSuccess"), "验证IsSuccess");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AcquireRefund_006() {
		Logger.start(true, "不输入必填项AppId,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
//			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
//			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("1000", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("appId not be empty", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AcquireRefund_007() {
		Logger.start(true, "不输入必填项OrderId,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
//			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
//			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("1000", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("orderId not be empty", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AcquireRefund_008() {
		Logger.start(true, "不输入必填项TradeNo,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
//			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("1000", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("tradeNo not be empty", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AcquireRefund_009() {
		Logger.start(true, "不输入必填项RefundNo,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt("1");
//			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("1000", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("refundNo not be empty", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AcquireRefund_010() {
		Logger.start(true, "不输入必填项RefundAmt,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
//			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("1000", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("refundAmt not valid", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AcquireRefund_011() {
		Logger.start(true, "不输入必填项TradeType,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
//			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("1000", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("must be greater than or equal to 1", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AcquireRefund_012() {
		Logger.start(true, "输入不存在TradeNo,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo("-1");
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			//??
			Logger.verifyEquals("3501", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("拒绝退款", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AcquireRefund_013() {
		Logger.start(true, "输入错误RefundAmt0,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt("0");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("1000", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("参数异常|RefundAmt should be greater than 0.", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AcquireRefund_014() {
		Logger.start(true, "输入错误RefundAmt-1,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt("-1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("1000", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("参数异常|RefundAmt should be greater than 0.", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AcquireRefund_015() {
		Logger.start(true, "输入错误TradeType-1,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(-1);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("1000", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("must be greater than or equal to 1", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AcquireRefund_016() {
		Logger.start(true, "未支付的订单部分退款,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(1);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("3501", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("拒绝退款", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AcquireRefund_017() {
		Logger.start(true, "重复提交部分退款金额,金额超过总额一半,返回成功(幂等)");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			aqb.setPayPrice("5");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt("3");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(1);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			acquirerefundCall.callService();
			Logger.verifyEquals("0", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			verifyDB(aqb, acquirerefundBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcquireRefund_018() {
		Logger.start(true, "招行输入全部退款金额,收单成功,生成RefundBatchNos");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("50");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
//			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("0", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			verifyDB(aqb, acquirerefundBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcquireRefund_019() {
		Logger.start(true, "招行优惠后输入全部退款金额,收单成功,生成RefundBatchNos");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("50");
			aqb.setPayPrice("5");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall50(aqb,"1");
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt("4");
//			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("0", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			verifyDB(aqb, acquirerefundBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcquireRefund_020() {
		Logger.start(true, "招行优惠后输入优惠前退款金额,失败");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("50");
			aqb.setPayPrice("5");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall50(aqb,"1");
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
//			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("3501", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("false", acquirerefundCall.getString("IsSuccess"), "验证IsSuccess");
			Logger.verifyEquals("拒绝退款", acquirerefundCall.getString("ErrorMessage"), "验证ErrorMessage");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcquireRefund_021() {
		Logger.start(true, "输入全部退款金额,带上字段bizNo,收单成功,生成RefundBatchNos");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("10");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
//			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setBizNo(TestDataManager.getRandomUUID().toString());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("0", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			verifyDB(aqb, acquirerefundBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcquireRefund_022() {
		Logger.start(true, "applepay输入全部退款金额,收单成功,生成RefundBatchNos");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("60");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
//			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("0", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			verifyDB(aqb, acquirerefundBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcquireRefund_023() {
		Logger.start(true, "baofu输入全部退款金额,收单成功,生成RefundBatchNos");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("70");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
//			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("0", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			verifyDB(aqb, acquirerefundBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcquireRefund_024() {
		Logger.start(true, "applepay输入全部退款金额,收单成功,生成RefundBatchNos");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("60");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
//			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("0", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			verifyDB(aqb, acquirerefundBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcquireRefund_025() {
		Logger.start(true, "9.支付宝花呗输入全部退款金额,收单成功,生成RefundBatchNos");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("9");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
//			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("0", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			verifyDB(aqb, acquirerefundBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AcquireRefund_026() {
		Logger.start(true, "17微信app小程序输入全部退款金额,收单成功,生成RefundBatchNos");
		try {
			AcquireOrderBean aqb = PaymentProxyCallService.initAcquireOrder("17");
			PaymentProxyCallService.acquireOrder(aqb);
			PaymentProxyCallService.notifyCall(aqb);
			acquirerefundBean.setAppId("AutoTest");
			acquirerefundBean.setOrderId(TestDataManager.getClientpaymentId());
			acquirerefundBean.setRefundAmt(aqb.getPayPrice());
//			acquirerefundBean.setRefundAmt("1");
			acquirerefundBean.setRefundNo(TestDataManager.getClientpaymentId());
			acquirerefundBean.setTradeNo(aqb.getOrderId());
			acquirerefundBean.setTradeType(2);
			acquirerefundCall.setData(acquirerefundBean);
			acquirerefundCall.callService();
			Logger.verifyEquals("0", acquirerefundCall.getString("ErrorCode"), "验证ErrorCode");
			verifyDB(aqb, acquirerefundBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void verifyDB(AcquireOrderBean aqb, AcquireRefundBean arb) throws Exception {
		Logger.comment("验证数据库RefundRequest");
		PaymentDefaultWapper paymentwapper = new PaymentDefaultWapper();
		PPBussinessOrder ppb = paymentwapper.selectPPBussinessorderByTraceId(aqb.getTraceId()).get(0);
		String businessoid = ppb.getBussinessOrderId();
		PPPayment ppm = paymentwapper.selectPPPaymentByBussinessOrderId(businessoid).get(0);
		String trandno = ppm.getPaymentId();
		List<RefundRequest> mlist = paymentwapper.selectRefundRequestByPaymentId(trandno);
		// 这里实际只会查出一条记录 trandno没有重复？
		for (int i = 0; i < mlist.size(); i++) {
			RefundRequest m = mlist.get(i);
			Logger.debug(m);
			if (m.getTraceId().equals(arb.getRefundNo())) {
				Logger.debug("selectRefundRequestByPaymentId:" + m);
				Logger.verifyEquals(0, m.getRefundStatus(), "验证RefundStatus");
				Logger.verifyEquals(0, m.getApproveStatus(), "验证ApproveStatus");
				Logger.verifyEquals(ppm.getInstitutionPaymentId(), m.getInstPaymentId(), "验证InstPaymentId");
				Logger.verifyEquals(arb.getAppId(), m.getAppId(), "验证AppId");
				Logger.verifyEquals(aqb.getCurrency(), m.getCurrencyType(), "验证CurrencyType");
				Logger.verifyEquals(arb.getOrderId(), m.getOrderId(), "验证OrderId");
				// Logger.verifyEquals(srbean.getTraceId(), m.get("TraceId"),
				// "验证TraceId");
				Logger.verifyEquals(arb.getTradeType().toString(), m.getTradeType().toString(), "验证TradeType");
				Logger.verifyEquals(arb.getTradeNo(), m.getTradeNo(), "验证TradeNo");
				Logger.verifyEquals(new Double(arb.getRefundAmt()), new Double(m.getRefundAmount().toString()), "验证RefundAmount");
				Logger.verifyNotNull(m.getRefundId(), "验证RefundId非空");
				if(arb.getBizNo()!=null){
					Logger.verifyEquals(arb.getBizNo(),m.getBizNo(),"验证bizno");
				}
			}
		}
	}
}